/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cl.darksigns.webstat.back.utils;

import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author _ViKtOr
 */
public class SendMail {

    private Session getJavamailjfotolog() throws NamingException {
        Context c = new InitialContext();
        return (Session) c.lookup("java:comp/env/javamail/jfotolog");
    }

    public void sendMail(String email, String subject, String body){
        try{
        Session javamailjfotolog = getJavamailjfotolog();
        MimeMessage message = new MimeMessage(javamailjfotolog);
        message.setSubject(subject);
        message.setRecipients(javax.mail.Message.RecipientType.TO, javax.mail.internet.InternetAddress.parse(email, false));
        message.setText(body);
        javax.mail.Transport.send(message);
        }catch(Exception ex){
            System.err.println(ex);
        }
    }

}
